/**
 * Gradient.java
 *
 * @created Jeudi 08/03/2007
 * 
 * @author bbrison
 */

package communication.thirdLayer;

import objects.Station;
import java.io.*;

public class Gradient implements Serializable {
 
    /**
     * The number of step between the node and the Sink
     */
    private int _step;

    /**
     * The station from which the message comes from
     */
    private Station _origin;

    /**
     * The type of the gradient
     */
    private int _type;

    /**
     * Constructor
     * @param step steps between node and sink
     * @param origin station from which the message comes from
     * @param type type of the gradient
     */
    public Gradient(int step, Station origin, int type) {
	_step = step;
	_origin = origin;
	_type = type;
    }

    /**
     * @return the steps between node and sink
     */
    public int getStep() {
	return _step;
    }
    
    /**
     * @return the station from which the message comes from
     */
    public Station getOrigin() {
	return _origin;
    }
    
    /**
     * @return the type of the gradient
     */
    public int getType() {
	return _type;
    }

    /**
     * Sets the type of the gradient
     * @param type the type of the gradient
     */
    public void setType(int type) {
	_type = type;
    }

    /**
     * Sets the number of step
     * @param step the number of step
     */
    public void setStep(int step) {
	_step = step;
    }
    

    /**
     * Redefinition of the equals method 
     * @param o the object(gradient) to be compared
     * @return true if the origin of two gradients is the same
     */
    public boolean equals(Object o){
	if((!(o instanceof Gradient)) || (o==null))
	    return false;
	else {
	    Station s =((Gradient)o).getOrigin();
	    return (s.getName()).equals(_origin.getName());
	}
    }

    public String toString(){
	return " Gradient : step="+ _step +" ; origin="+_origin+" ; type="+_type+"\n";
    }
}
